<?php
session_start();

if(!isset($_SESSION['logged_in']))
{
	header ("Location: login.php");
}

?>
<!doctype html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>
			The Cobra Snake - ADMIN
		</title>
		<style type="text/css">
			
			body,td,th {
				font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
				font-size: 10px;
				color: #999;
				background-color: black;
				text-align: center;
			}
			body {
				background-color: #000;
				margin-left: 0px;
				margin-top: 0px;
				margin-right: 0px;
				margin-bottom: 0px;
			}
			h2{
				height: 20px;
				clear: both;
			}
			.removable_tag_list{ height: 75px; overflow: auto;}
			
			
			#mainContainer{
				text-align:center;
				display: block;
			}
			#editableGalleries { width:600px; float: none; position: absolute; top: 650px; left: 50%; margin-left: -300px; overflow: auto;} 
			
			#photosWithFields { width:680px; float: none; position: absolute; top: 770px; left: 50%; margin-left: -340px; overflow: auto;} 
			
			#thumbsList, #galleryList, .topLinks { list-style: none; margin: 0; padding: 0; border: none; } 
			#editableGalleries li
			{
				border: 1px solid #000000; float:left; margin: 0; margin-right:10px; margin-bottom: 10px;
			}
			
			#photosWithFields li { border: 1px solid #ffffff; float:left; margin: 0; height: auto; width: 200px; padding-left: 11px; padding-right: 11px; padding-top: 11px; padding-bottom: 11px; text-align: left;} 
			#photosWithFields li ul li{ border:none; float:none; margin-bottom: 3px; height: 16px; width: 150px;padding-left: 0; padding-right: 0px; padding-top: 0;  padding-bottom: 0px;}
			#guestCheck {display: none;  height: 400px; width:800px; position: relative; left:50%; margin-left: -400px; margin-top: 270px;}
			#guestCheckImg, #guestCheckFields
			{  
				display: -moz-inline-stack;
		        display: inline-block;
		        vertical-align: top;
		        zoom: 1;
		        *display: inline; 
	        }
			
			#guestCheckFields{
				position: relative;
				width: auto;
				margin-left: 20px;
				text-align: justify;
				line-height: 49px;
				overflow: hidden;
				margin-top:-20px;
				width: 395px;
			}
			#guest_check_form{
				position: relative;
			}
			
			#guest_check_form span{
				line-height: normal;
			}
			
			#guestCheckContent
			{
				width:100%;
				height: auto;
				display: block;
				margin-top: 20px;
			}
			
			#new_category_form { padding:10px;  
		        height:60px;
		        width: 300px;  
				border: solid 2px #DFDFDF; 
				background-color: #eeeeee;
				line-height: normal;
				}
				
			#editBtn, #previewBtn
			{
				font-size: 16px;
				font-weight: bold;
			}
			.editableGalleryThumb
			{
				cursor: pointer;
			}
    
			.handle { cursor: url(images/moveCursor.png),url(images/moveCursor.gif), auto; }
			.removable_tag_list {list-style: none; margin: 0; padding: 0; border: none;}
			.removable_tag { background:#eee url('js/jquery.plupload.queue/img/delete.gif') no-repeat right top; cursor: pointer; margin-bottom: 3px;}
			
			
			.guest_check_form_input
			{  
		        width:99px;  
		        padding:10px;  
		        outline:none;  
		        height:16px;
		        font-size: 16px;
		        font-weight: bold;
				border: solid 2px #00fb34; 
		    }
			.emptyInputWarning
			{  
				border:solid 2px #FF0000;  
				background:#FFDDDD;  
				color:#000;  
			}  
			
			.photo_form, .removable_tag_list
			{
				width: 190px;
			}
			
			
			a:link    {color:green;}
			a:visited {color:green;}
			a:hover   {color:red;}
			a:active  {color:yellow;} 
			
			/* 	STYLE OVERRIDES		 */
			
			#gc_month, #gc_topcolor, #gc_bottomcolor
			{
				width: 40px;
			}
			#gc_year, #gc_day, #gc_topsize, #gc_bottomsize
			{
				width: 15px;
			}
			#gc_galleryname
			{
				width: 141px;
			}
			
			#html5_uploader
			{
				position: relative;
				left:50%;
				margin-left: -400px;
				margin-top: 265px;
			}
						
			.cobraButtonDynamic
			{
				height: 58px;
				width:auto;
				background: url("../img/btnLeft.png") no-repeat left top;				
				margin: 0;
				padding: 0;
				padding-left: 15px;
				
				
				display: -moz-inline-stack;
		        display: inline-block;
		        vertical-align: top;
		        zoom: 1;
		        *display: inline;

			}
			
			.cobraButtonDynamic a
			{
				height: 58px;
				width:auto;
				background: url("../img/btnRight.png") no-repeat right top;
				
				position: relative;
				
				display: -moz-inline-stack;
		        display: inline-block;
		        vertical-align: top;
		        zoom: 1;
		        *display: inline;
			}
			.cobraButtonDynamic a img
			{
				margin-top: 10px;
			}

/* 		HEADER	 */
			
			#headerContainer 
			{ 
				position: relative;
				position: fixed; top:0px; left:0px; background-color: black; height:auto; width:100%; text-align: center;
			}
			
			#headerMenu		    
		    {
		    	height: 100px;
		    	width: 790px;
		    	background:  url('../img/headerBG.jpg') no-repeat 0 center;
		    	
		    	position: relative;
		    	left: 50%;
		    	margin-left: -375px;
		    	margin-top: 30px;
		    }
		    #theCobraSnakeLogo
		    {
		    	margin-top: 60px;
		    }
		    .navButtons
		    {
		    	list-style: none;
		    	margin: 0;
		    	padding: 0;
		    }
		    
		    .navButtons li
		    {
		    	width: 166px;
		    	height: 100px;
		    	float: left;
		    }

			.navButtons li img
		    {
		    	margin-top: 40px;
		    } 
		    
		    .navButtons li:nth-child(3) 
		    {
		    	width: 144px;
			}
			
			
		    .navButtons li:nth-child(4) 
		    {
		    	width: 144px;
		    	text-align: center;
			}
			
			.navButtons li:nth-child(4) img:nth-child(1)
		    {
		    	margin-top: 20px;
			}
			.navButtons li:nth-child(4) img:nth-child(2)
		    {
		    	margin-top: 0px;
			}
			
			.search_input
		    {
		    	margin-top: 38px;
		    	width:85px;  
		        padding:8px;  
		        outline:none;  
		        height:18px;
		        font-size: 16px;
		        font-weight: bold;
				border: solid 3px #ff0000; 	
		    }
/* /HEADER  */

		</style>
		<link type="text/css" rel="stylesheet" href="css/syronex-colorpicker.css" />
		<!-- <link type="text/css" rel="stylesheet" href="css/jquery.miniColors.css" /> -->
		<link rel="stylesheet" href="js/jquery.plupload.queue/css/jquery.plupload.queue.css"
		type="text/css" media="screen" />
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
		                		                    
		</script>
		<script type="text/javascript" src="../js/jquery-ui-1.7.1.custom.min.js">
		                		                    
		</script>
		<script type="text/javascript" src="../js/functions.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/plupload.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/plupload.html5.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/jquery.plupload.queue/jquery.plupload.queue.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/syronex-colorpicker.js"></script>
		
		<!--<script type="text/javascript" src="js/jquery.miniColors.js"></script>
		
		<script src="js/cufon-yui.js" type="text/javascript"></script>
		<script src="js/TCS_400.font.js" type="text/javascript"></script>-->
		<script type="text/javascript">
			//Cufon.replace('body'); // Works without a selector engine
			//Cufon.replace('#sub1'); // Requires a selector engine for IE 6-7, see above
		</script>
	</head>
	<body>
		<div id="mainContainer">
				<div id="html5_uploader" style="width: 795px; height: 400px;">
					You browser doesnt support native upload. Try The latest Firefox or Safari.
				</div>
				
				<div id="guestCheck"><span id="editBtn" class="cobraButtonDynamic"><a href="#"><img src="../pngfont.php?bgcolor=ffa1a2&color=000&size=14&font=fonts/TCS2.ttf&text=EDIT GALLERY " alt="EDIT" border="0"></a></span><span id="previewBtn" class="cobraButtonDynamic"><a href="#"><img src="../pngfont.php?bgcolor=ffa1a2&color=000&size=14&font=fonts/TCS2.ttf&text=PREVIEW GALLERY " alt="PREVIEW" border="0"></a></span><!-- <button id="editBtn"><img src="../pngfont.php?bgcolor=ddd&color=f00&size=14&font=fonts/TCS2.ttf&text=EDIT GALLERY " alt="EDIT" border="0"></button><button id="previewBtn"><img src="../pngfont.php?bgcolor=ddd&color=f00&size=14&font=fonts/TCS2.ttf&text=PREVIEW GALLERY" alt="PREVIEW" border="0"></button> -->
					<div id="guestCheckContent">
						<img id="guestCheckImg" src="" border="0" />
						<div id="guestCheckFields"><form class="guest_check_form">
								<span class="publishing">HIDE GALLERY: <input class="publishing_radio_buttons" type="radio" name="public" value="NO" checked="true" id="gc_private" />   SHOW GALLERY: <input class="publishing_radio_buttons" type="radio" name="public" value="YES" id="gc_public"/></span><br />
								<span><input class="guest_check_form_input"  type="text" name="month" value="JAN" id="gc_month" />  /  <input  class="guest_check_form_input"  type="text" name="day" value="01" id="gc_day" />  /  <input  class="guest_check_form_input"  type="text" name="year" value="99" id="gc_year" /></span><br />
								
								<span><input  class="guest_check_form_input"  type="text" name="topText" value="TOP TEXT" id="gc_toptext" /> <input  class="guest_check_form_input"  type="text" name="topSize" value="11"  id="gc_topsize" /> <input  class="guest_check_form_input colors"  type="hidden" name="topColor" value="#000000"  id="gc_topcolor" /><span class="color_paletteA" rel="gc_topcolor"></span></span><br />
								
								<span><input  class="guest_check_form_input"  type="text" name="bottomText" value="BOTTOM TEXT"  id="gc_bottomtext" /> <input  class="guest_check_form_input"  type="text" name="bottomSize" value="11"  id="gc_bottomsize" /><input  class="guest_check_form_input colors"  type="hidden" name="bottomColor" value="#000000"  id="gc_bottomcolor" /><span class="color_paletteB" rel="gc_bottomcolor"></span></span><br />
								
								<span><input  class="guest_check_form_input"  type="text" name="galleryName" value=""  id="gc_galleryname" /> <span id="gc_gallerypath"></span></span><br />
								
								<span><select name="category" id="categorySelector"><option value="new">CREATE A NEW ONE…</option></select></span>					
							</form>
							<form id="new_category_form">
							NEW CITY: <input  type="text" name="category"  id="nc_category" /><input  class="categoryColor"  type="hidden" name="color" value="#000000"  id="nc_color" /><span class="color_paletteC" rel="nc_color"> </span><input type="submit" value="CREATE" />
							</form>
						</div>
					</div>
				</div><br />
				<div id="photosWithFields">
					<img src="../pngfont.php?bgcolor=000000&color=f00&size=17&font=fonts/TCS2.ttf&text=DRAG PHOTOS " alt="DRAG PHOTOS TO CHANGE ORDER" border="0">
					<img src="../pngfont.php?bgcolor=000000&color=f00&size=17&font=fonts/TCS2.ttf&text=TO CHANGE ORDER " alt="DRAG PHOTOS TO CHANGE ORDER" border="0"><br />
					<ul id="thumbsList" />
				</div><br />
				<div id="editableGalleries">
					<img class="gallerySectionLabel" src="../pngfont.php?bgcolor=000000&color=f00&size=20&font=fonts/TCS2.ttf&text=EDIT ANY " alt="EDIT ANY GALLERY BELOW" border="0">
					<img class="gallerySectionLabel" src="../pngfont.php?bgcolor=000000&color=f00&size=20&font=fonts/TCS2.ttf&text=GALLERY BELOW " alt="EDIT ANY GALLERY BELOW" border="0"><br />
					<ul id="galleryList" />
				</div>
			</div>
			
			<div id="headerContainer">
				<a href="http://thecobrasnake.com/" target="_self"><img id="theCobraSnakeLogo" src="../pngfont.php?bgcolor=000000&color=fffb00&size=28&font=fonts/TCS2.ttf&text=THE COBRA SNAKE " alt="THE COBRA SNAKE" border="0"></a>
				<div id="headerMenu">
					<ul class="navButtons">
						<li><a href="http://thecobrasnake.com/" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=ff0000&size=11&font=fonts/TCS2.ttf&text=PHOTOS " alt="THE COBRA SNAKE" border="0"></a></li>
						<li><a href="http://shop.thecobrasnake.com/collections/cool-stuff" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=7dfc7d&size=11&font=fonts/TCS2.ttf&text=STORE " alt="THE COBRA SNAKE" border="0"></a></li>
						<li><a href="#" target="_self"><img class="search_label" src="../pngfont.php?bgcolor=f6f9fd&color=c0c0c0&size=11&font=fonts/TCS2.ttf&text=SEARCH " alt="THE COBRA SNAKE" border="0"></a><input type="text" class="search_input"></input></li>
						<?php 
						if(isset($_SESSION['logged_in_admin']))
						{
							?>
							<li><a href="create_user.php" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=7dc9ff&size=11&font=fonts/TCS2.ttf&text=MANAGE " alt="THE COBRA SNAKE" border="0"><img src="../pngfont.php?bgcolor=f6f9fd&color=7dc9ff&size=11&font=fonts/TCS2.ttf&text=LOGINS " alt="THE COBRA SNAKE" border="0"></a></li>
							<?php
						}else
						{
							?>
							<li>&nbsp;</li>
							<?php
						}
						?>
						<li><a href="./logout.php" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=ffc77a&size=11&font=fonts/TCS2.ttf&text=LOG OUT " alt="THE COBRA SNAKE" border="0"></a></li>
					</ul>
				</div>
			</div>
		<script type="text/javascript">
			  var authorId = <?= $_SESSION['authorId'];?>;
		
              var today = new Date();
              
              
              var photoGalleryId = 0;
              
              
              // initial values for the guest check
              
              var newfilename = "covers/0.jpg";
              var photoName = "000";
              var month = monthFromNum( today.getMonth() );
              var day = today.getDate();
              var year = today.getFullYear().toString().substr(2,2);
              var topText = "TOP TEXT";
              var bottomText = "BOTTOM TEXT";
              var topSize = 11;
              var bottomSize = 11;
              var topColor = "#000000";
              var bottomColor = "#000000";
              var galleryName = "";
              
              
              

              $(function()
              {
              	
				$('.search_input').hide();
				$('.search_input').val("");
              
              	$("#photosWithFields").hide();
              	
				$("#gc_month").val(month);
				$("#gc_day").val(day);
				$("#gc_year").val(year);
				$("#gc_toptext").val(topText);
				$("#gc_topsize").val(topSize);
				$("#gc_topcolor").val(topColor);
				$("#gc_bottomtext").val(bottomText);
				$("#gc_bottomsize").val(bottomSize);
				$("#gc_bottomcolor").val(bottomColor);
				$("#gc_galleryname").val(galleryName);
              	
              	webservice.photos.getGalleriesByAuthorId(authorId, function(galleriesJSON){
              		if(galleriesJSON)
              		{
              			var jList = $("#galleryList");
                  		
                  		// Loop over each value in the array.
      					$.each(galleriesJSON, function(intIndex, objValue)
      					{
      						var htmlStr = "";
      						htmlStr += '<img src="../timthumb.php?src=' + objValue.cover_url + '&w=127&h=197" border="0" />';
      						jList.append( $("<li class='editableGalleryThumb' rel='" + objValue.id + "'>" + htmlStr + "</li>") );
      					});
      					
      					if($("#galleryList li").length < 1)
      					{
      						$(".gallerySectionLabel").hide();
      					}
              		}
              	});
              	
              	$('.search_label').click( function(){
					$('.search_label').hide();
					$('.search_input').show();
				});
				$('.search_input').change(function(){
					window.location="../gallery.php?search="+$(this).val();
				});
                
                $("#editBtn").click( function () {
                	$("#guestCheckFields").show();
                	$(".photo_form").show();
                	$("#editBtn").hide();
               		$("#previewBtn").show(); 	
                 });
                
                $("#previewBtn").click( function () {
                	$("#guestCheckFields").hide();
                	$(".photo_form").hide();
                	$("#editBtn").show();
               		$("#previewBtn").hide(); 	
                });
                
                $('.color_paletteA').colorPicker(
				{			
				  defaultColor:0,
				  color: ["#000000", "#e500e2","#ffb400","#008aff","#00d40f","#f0ff00","#ff0000"],
				  extra: $(".color_paletteA").attr('rel'),
				  click:function(c, o){
				    //alert(c);
				    //alert(  o  );
				    $("#"+o).val(c);
					$('#gc_toptext').trigger('keyup');
				  }
				});
				$('.color_paletteB').colorPicker(
				{			
				  defaultColor:0,
				  color: ["#000000", "#e500e2","#ffb400","#008aff","#00d40f","#f0ff00","#ff0000"],
				  extra: $(".color_paletteB").attr('rel'),
				  click:function(c, o){
				    //alert(c);
				    //alert(  o  );
				    $("#"+o).val(c);
					$('#gc_toptext').trigger('keyup');
				  }
				});
				$('.color_paletteC').colorPicker(
				{			
				  defaultColor:0,
				  color: ["#000000", "#e500e2","#ffb400","#008aff","#00d40f","#f0ff00","#ff0000"],
				  extra: $(".color_paletteC").attr('rel'),
				  click:function(c, o){
				    //alert(c);
				   // alert(  o  );
				    $("#"+o).val(c);
				  }
				});


              	$('#new_category_form').submit(function() {
				  
					var targetForm = $( $(this).closest("form") );
					
					var categoryData = new Array();

					$.each( targetForm.serializeArray(), function(i, field) {
					    categoryData[field.name] = field.value;
					});
					
					
					var title = categoryData.category;
					var color = categoryData.color;
					
					
					$("#nc_category").val("");
					$("#nc_color").val("#000000");
					$("#new_category_form").hide();
					$("#photosWithFields").css("top", "770px");
					
					webservice.photos.saveNewCategory(title, color, function(newCategoryId)
					{
						// create the category and when it returns:
						
						$('#categorySelector').append( $('<option>', { value : newCategoryId }).text(title).css( { "background-color": color} ) );
						
						$("#categorySelector").val(newCategoryId);
						
						//SAVE GALLERY CATEGORY	
						categorySelected();
					});
					
				  
				  return false;
				});
				
				$("#new_category_form").hide();
              
              	// get list of cities and add them to the drop down 
				webservice.photos.getAllCategories( function(categoriesJSON){
					$.each(categoriesJSON, function(intIndex, objValue)
					{ 
						$('#categorySelector').prepend( $('<option>', { value : objValue.id }).text(objValue.title).css( { "background-color": objValue.color} ) ); 
					});
					
					$('#categorySelector').prepend( $('<option>', { value : "" }).text("SELECT A CITY…") );
					$("#categorySelector").val('');
					
				});
				
				$('#categorySelector').change( categorySelected );
				
				function categorySelected()
				{
					//alert( $("#categorySelector option:selected").val() );
					var selectedValue = $("#categorySelector option:selected").val();
					if(selectedValue == "new")
					{
						// show new category form
						$("#new_category_form").show();
						$("#photosWithFields").css("top", "870px");
					}else
					{
						// save category
						webservice.photos.saveGalleryCategory(photoGalleryId, selectedValue, function(msg){
							/* alert(msg); */
						});
					}
				}
				
				$(".publishing_radio_buttons").change(function(){
					var publicStatus = 0;
					switch( $(this).val() )
					{
						case "YES":
							publicStatus = 1;
						break;
						case "NO":
							publicStatus = 0;
						break;
					}
					webservice.photos.setGalleryPublicStatus(photoGalleryId, publicStatus, function(msg){
							/* alert(msg); */
						});
					
				});
              
              	// Setup html5 uploader
              	$("#html5_uploader").pluploadQueue(
              	{
              		// General settings
              		runtimes: 'html5',
              		url: 'upload.php',
              		max_file_size: '20mb',
              		chunk_size: '1mb',
              		unique_names: true,
              		filters: [
              		{
              			title: "Image files",
              			extensions: "jpg,gif,png"
              		}, 
              		{
              			title: "Zip files",
              			extensions: "zip"
              		}],

              		// Resize images on clientside if we can
              		resize: {
              			width: 1067,
              			height: 711,
              			quality: 90
              		} 
              	});

              	var uploader = $("#html5_uploader").pluploadQueue();

              	uploader.bind('UploadComplete', function(uploader, filez)
              	{
              		//alert('UPLOADED files: ' + filez.length);
              		// first create a gallery
              		webservice.photos.createGallery( authorId,function(galleryId)
              		{
              			//alert("GALLERY CREATED WITH ID: "+galleryId);
              			photoGalleryId = galleryId;

              			// create a list of file names
              			fileList = "";
              			for (i = 0; i < filez.length; i++)
              			{
              				if (i == filez.length - 1)
              				{
              					fileList += filez[i].id;
              				}
              				else
              				{
              					fileList += filez[i].id + ",";
              				}

              			}

              			// add them to the gallery 
              			webservice.photos.addPhotos(galleryId, fileList, function(message)
              			{
              				// get photos with their corresponding id's
              			    showEditableGallery(galleryId);
              			});
              			
              		});
              		
              		
              		
              		
              		

              	});

              	

              	$("#thumbsList").sortable(
              	{
              		handle: '.handle',
              		update: function()
              		{
              			var orderDataArr = new Array();
              			$("#thumbsList li").each(function(index)
              			{
              				orderDataArr.push(index + ': ' + $(this).attr("rel"));
              			});
              			webservice.photos.setNewGalleryOrder(photoGalleryId, orderDataArr.toString(), function(msg)
              			{
              				//alert(msg);
              			});
              		}
              	});
              	
              	$('.editableGalleryThumb').live('click', function(){
              	
              		var targetGalleryId = $(this).attr('rel');
              		showEditableGallery(targetGalleryId);
              	});

				

              	$('.photo_form_input').live('change', function()
              	{
              		var photo = {};
					
					
					
					$.each($( $(this).closest("form") ).serializeArray(), function(i, field) {
					    photo[field.name] = field.value;
					    //alert(field.name + " = " + field.value);
					});
					
					photo.public = ($(this).closest("form").find(".publishCheckbox").attr('checked') )? 1 : 0;
					
					webservice.photos.updatePhotoProperties(photo.id, photo.tags, photo.public, function(msg){
              			var cleared = false;
          				$.each(msg, function(intIndex, objValue)
      					{
      						var tagList = $("#tags_"+objValue.photo_id);
      						var tagsInput = $("#tags_input_"+objValue.photo_id);
      						
      						tagsInput.val("");
      						
      						if(!cleared)
      						{
      							cleared = true;
          						tagList.html("");
      						}
      						

      						tagList.append( $("<li class='removable_tag' rel='" + objValue.id + "'>" + objValue.tag + "</li>") );
          				
          				});
          				
          			});
          			
              	});
              	
              	$('.guest_check_form_input').live('keyup',guestCheckUpdate);
              	
              	/*
$('.colors').live('blur',guestCheckUpdate);
              	$(".colors").miniColors({
					
					change: function(hex, rgb) {
						$(this).val(hex);
					}
					
				});
				
				$(".categoryColor").miniColors({
					
					change: function(hex, rgb) {
						$(this).val(hex);
					}
					
				});
*/
				
              	function guestCheckUpdate()
              	{
              		var guestCheckData = {};
					
					var doGuestCheckUpdate = true;
					var targetForm = $( $(this).closest("form") );
					$.each( targetForm.serializeArray(), function(i, field) {
					    guestCheckData[field.name] = field.value;
					    if(field.value.length < 1 )
					    {
					    	doGuestCheckUpdate = false;
					    }
					});
					
					targetForm.find(':input').each(function(i) 
					{
						if( $(this).val() == "")
						{
							$(this).addClass('emptyInputWarning');
						}else
						{
							$(this).removeClass('emptyInputWarning');
						}
				    });

					
					if(doGuestCheckUpdate)
					{
						month = (guestCheckData.month)? guestCheckData.month : "00";
						day = (guestCheckData.day)? guestCheckData.day : "00";
						year = (guestCheckData.year)? guestCheckData.year : "00";
						topText = (guestCheckData.topText)? guestCheckData.topText : " ";
						bottomText = (guestCheckData.bottomText)? guestCheckData.bottomText : " ";
						topSize = (guestCheckData.topSize)? guestCheckData.topSize : "10";
						bottomSize = (guestCheckData.bottomSize)? guestCheckData.bottomSize : "10";
						topColor = (guestCheckData.topColor)? guestCheckData.topColor : "#000000";
						bottomColor = (guestCheckData.bottomColor)? guestCheckData.bottomColor : "#000000";
						galleryName = (guestCheckData.galleryName)? guestCheckData.galleryName : topText+ " " +bottomText;
													
						$("#gc_month").val(month);
						$("#gc_day").val(day);
						$("#gc_year").val(year);
						$("#gc_toptext").val(topText);
						$("#gc_topsize").val(topSize);
						$("#gc_topcolor").val(topColor);
						$("#gc_bottomtext").val(bottomText);
						$("#gc_bottomsize").val(bottomSize);
						$("#gc_bottomcolor").val(bottomColor);
						
                  		webservice.photos.makeGuestCheck(photoGalleryId, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, function(updatedFileName){
							$("#guestCheckImg").attr( 'src', updatedFileName );
                  		});
                  		
                  		// save the date and name of the gallery
                  		webservice.photos.saveGalleryData(photoGalleryId, month, day, year, galleryName, topText, bottomText, topColor, bottomColor, function(msg){
							//alert(msg);
                  		});
                  		
                  		

					}					
          				
          			
              	};

              	
              	$('form').live('submit', function(e){
              		e.preventDefault();
              	});
              	
              	$('.photo_form_cover').live('change', function(){
              		$('input[type=radio]').each(function(){
						$(this).attr('checked', false);
					});
              		
              		$(this).attr('checked', true);
              		
              		photoName = $(this).attr('rel');
              		
              		
              		webservice.photos.makeGuestCheck(photoGalleryId, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, function(updatedFileName){
						$("#guestCheckImg").attr( 'src', updatedFileName );
              		});

              	});
              	
              	
              	$('.removable_tag').live('click', function()
              	{
              		var tagToRemove = $(this);
              		webservice.photos.removeTag($(this).attr('rel'), function(msg){
          				tagToRemove.remove();	          				
          			});
              		
              	});
              	
              	
              	
				
				function dump(obj) 
				{
				    var out = '';
				    for (var i in obj) 
				    {
				        out += i + ": " + obj[i] + "\n";
				    }
				
				}
              	

              });
              
              function monthFromNum(monthNum)
              {
              	var month=new Array(12);
              	month["00"]="JAN";
				month[0]="JAN";
				month[1]="FEB";
				month[2]="MAR";
				month[3]="APR";
				month[4]="MAY";
				month[5]="JUN";
				month[6]="JUL";
				month[7]="AUG";
				month[8]="SEP";
				month[9]="OCT";
				month[10]="NOV";
				month[11]="DEC";
              	
              	return month[monthNum];
              }
              
              function showEditableGallery(galleryId)
              {
              	$("#editableGalleries").hide();
              	$("#editBtn").hide();
                $("#previewBtn").show();
              	photoGalleryId = galleryId;
              	webservice.photos.getGalleryImages(galleryId, function(photosJSON)
  				{
  					$("#photosWithFields").show();
  					
  					$("#thumbsList li").remove();
  					var jList = $("#thumbsList");

  					// Loop over each value in the array.
  					$.each(photosJSON, function(intIndex, objValue)
  					{
  						var htmlStr = "";
  						htmlStr += '<img src="../timthumb.php?src=photographs/' + objValue.url + '.JPG&w=200&h=133" border="0" class="handle" />';
  						htmlStr += '<form class="photo_form">';
  						htmlStr += '<input class="photo_form_input publishCheckbox" type="checkbox" name="public"  checked="checked"/> PUBLIC  ';
  						if(intIndex == 0)
  						{
  							htmlStr += '<input class="photo_form_cover albumCoverRadio" type="radio" name="cover" rel="' + objValue.url + '" value="yes" checked="yes" /> ALBUM COVER<br />';
  						}else
  						{
  							htmlStr += '<input class="photo_form_cover albumCoverRadio" type="radio" name="cover" rel="' + objValue.url + '" value="yes" /> ALBUM COVER<br />';
  						}
  						htmlStr += '<input class="" type="hidden" name="id" value="' + objValue.id + '"/>';
  						htmlStr += 'ENTER TAGS HERE: <input id="tags_input_'+objValue.id+'" class="photo_form_input" type="text" name="tags" />';
  						htmlStr += '<ul class="removable_tag_list" id="tags_'+objValue.id+'"></ul>';
  						htmlStr += '</form>';
  						jList.append( $("<li id='listItem_" + intIndex + "' rel='" + objValue.id + "'>" + htmlStr + "</li>") );
  						
  						if(intIndex == 0)
  						{
  							photoName = objValue.url;
  							
  							//getGalleryInfo
  							webservice.photos.getGalleryData(photoGalleryId, function(dataJSON)
  							{
  								if(dataJSON[0].cover_url != "")
      							{
      								$("#guestCheck").show();
									$("#guestCheckImg").attr( 'src', "../"+dataJSON[0].cover_url );
									
									var dateStr = dataJSON[0].date;
									var dateArr = dateStr.split('-');
									
									month = monthFromNum( parseInt(dateArr[1]) - 1);
									day = dateArr[2];
									year = dateArr[0].substr(2);
									topText = dataJSON[0].top_text;
									bottomText = dataJSON[0].bottom_text;
									topSize = 11;
									bottomSize = 11;
									topColor = dataJSON[0].top_color;
									bottomColor = dataJSON[0].bottom_color;
									galleryName = dataJSON[0].name;
									
									$("#gc_public").attr('checked', (dataJSON[0].public == '1') );
									$("#gc_private").attr('checked', (dataJSON[0].public == '0') );
									
									$("#gc_month").val(month);
									$("#gc_day").val(day);
									$("#gc_year").val(year);
									$("#gc_toptext").val(topText);
									$("#gc_topsize").val(topSize);
									$("#gc_topcolor").val(topColor);
									$("#gc_bottomtext").val(bottomText);
									$("#gc_bottomsize").val(bottomSize);
									$("#gc_bottomcolor").val(bottomColor);
									$("#gc_galleryname").val(galleryName);
									
									$("#categorySelector").val(dataJSON[0].category_id);
									
									$("#html5_uploader").hide();
									$('.photo_form_input').trigger('change');
      							}else
      							{
      								webservice.photos.makeGuestCheck(photoGalleryId, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, function(updatedFileName){
										$("#guestCheck").show();
										$("#guestCheckImg").attr( 'src', updatedFileName );
										$("#html5_uploader").hide();
	      		
			                  		});
      							}

  							});
  								
  						}
  					}

  					);
  				}

  				);
              	
              }
		</script>
	</body>

</html>